package ${domain}.frame.schedule;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.Assert;

import java.time.Duration;
import java.util.concurrent.ScheduledFuture;

/**
 * 间隔重复任务，任务A执行结束后，间隔指定时间后开始执行B
 * 倘若A未执行完，B一直处于等待状态
 *
 * @author wangbing
 * @version 0.0.1
 * @since 2020-01-01
 */
public abstract class RunDelayRepeatTask extends RunTask {

    public abstract Duration interval();

    @Override
    public ScheduledFuture<?> schedule(ThreadPoolTaskScheduler poolTaskScheduler) {
        Assert.notNull(poolTaskScheduler, "ThreadPoolTaskScheduler must not be null");
        return poolTaskScheduler.scheduleWithFixedDelay(this, interval());
    }
}
